#region Developer's comment header
/* aspnet_Users.cs
 * 
 * author:    DS2171
 * copyright: DS2171
 * 
 * history:   15/11/2010, DS2171: Created.
 *
 */
#endregion
#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;

using Chili.Opf3;
using Chili.Opf3.Relations;


#endregion

namespace DocManagerORM.Entità
{
	/// <summary>
	/// Persistent object for the "aspnet_Users" table.
	/// </summary>
	[Serializable]
	[Persistent("aspnet_Users")]
	public partial class aspnet_Users : IObjectNotification, ISelfContainingObject, INotifyPropertyChanged, Iaspnet_Users
	{
		#region Fields

		private Guid _applicationId = Guid.NewGuid();
		private Guid _userId = Guid.NewGuid();
		private string _userName;
		private string _loweredUserName;
		private string _mobileAlias;
		private bool _isAnonymous;
		private DateTime _lastActivityDate;

		#endregion

		#region Relations

		[Relation("UserId = UserId")]
		private ObjectSetHolder<aspnet_Membership> _aspnet_Membership = new ObjectSetHolder<aspnet_Membership>();

		/// <summary>
		/// Gets and sets a set of connected "aspnet_Membership" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<aspnet_Membership> aspnet_Membership
		{
			get { return _aspnet_Membership.InnerObject; }
		}

		[Relation("UserId = UserId")]
		private ObjectSetHolder<aspnet_PersonalizationPerUser> _aspnet_PersonalizationPerUser = new ObjectSetHolder<aspnet_PersonalizationPerUser>();

		/// <summary>
		/// Gets and sets a set of connected "aspnet_PersonalizationPerUser" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<aspnet_PersonalizationPerUser> aspnet_PersonalizationPerUser
		{
			get { return _aspnet_PersonalizationPerUser.InnerObject; }
		}

		[Relation("UserId = UserId")]
		private ObjectSetHolder<aspnet_Profile> _aspnet_Profile = new ObjectSetHolder<aspnet_Profile>();

		/// <summary>
		/// Gets and sets a set of connected "aspnet_Profile" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<aspnet_Profile> aspnet_Profile
		{
			get { return _aspnet_Profile.InnerObject; }
		}

		[Relation("ApplicationId = ApplicationId", PersistRelationship = PersistRelationships.ChildFirst)]
		private ObjectHolder<aspnet_Applications> _aspnet_Applications = new ObjectHolder<aspnet_Applications>();

		/// <summary>
		/// Specifies the connected "aspnet_Applications" persistent object.
		/// </summary>
		[XmlIgnore]
		public aspnet_Applications aspnet_Applications
		{
			get { return _aspnet_Applications.InnerObject; }
			set { _aspnet_Applications.InnerObject = value; }
		}

		[Relation("UserId = UserId")]
		private ObjectSetHolder<aspnet_UsersInRoles> _aspnet_UsersInRoles = new ObjectSetHolder<aspnet_UsersInRoles>();

		/// <summary>
		/// Gets and sets a set of connected "aspnet_UsersInRoles" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<aspnet_UsersInRoles> aspnet_UsersInRoles
		{
			get { return _aspnet_UsersInRoles.InnerObject; }
		}

		[Relation("UserId = Fk_IDUser_Destinatario; UserId = Fk_IDUser_Mittente; UserId = Fk_IDUser_Destinatario")]
		private ObjectSetHolder<Iters> _iters = new ObjectSetHolder<Iters>();

		/// <summary>
		/// Gets and sets a set of connected "Iters" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<Iters> Iters
		{
			get { return _iters.InnerObject; }
		}

		#endregion

		#region Properties

		/// <summary>
		/// Returns the identifier of the persistent object. Mandatory.
		/// </summary>
		[Field("ApplicationId", AllowDBNull = false, Identifier = true)]
		public Guid ApplicationId
		{
			get 
			{ 
				return _applicationId; 
			}
			set 
			{
				_applicationId = value;

				OnRowChanged("ApplicationId");
			}
		}

		/// <summary>
		/// This property is mapped to the "UserId" field.  Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("UserId", AllowDBNull = false)]
		public Guid UserId
		{
			get 
			{ 
				return _userId; 
			}
			set 
			{
				_userId = value;

				OnRowChanged("UserId");
			}
		}

		/// <summary>
		/// This property is mapped to the "UserName" field. Length must be between 0 and 256 characters. Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("UserName", AllowDBNull = false)]
		public string UserName
		{
			get 
			{ 
				return _userName; 
			}
			set 
			{
				if (value == null)
					throw new ArgumentNullException("value", "Value is null.");
				if (value != null && value.Length > 256)
					throw new ArgumentException("Value length must be between 0 and 256 characters.");

				_userName = value;

				OnRowChanged("UserName");
			}
		}

		/// <summary>
		/// Returns the identifier of the persistent object. Mandatory.
		/// </summary>
		[Field("LoweredUserName", AllowDBNull = false, Identifier = true)]
		public string LoweredUserName
		{
			get 
			{ 
				return _loweredUserName; 
			}
			set 
			{
				if (value == null)
					throw new ArgumentNullException("value", "Value is null.");
				if (value != null && value.Length > 256)
					throw new ArgumentException("Value length must be between 0 and 256 characters.");

				_loweredUserName = value;

				OnRowChanged("LoweredUserName");
			}
		}

		/// <summary>
		/// This property is mapped to the "MobileAlias" field. Length must be between 0 and 16 characters. 
		/// Storage comment: .
		/// </summary>
		[Field("MobileAlias")]
		public string MobileAlias
		{
			get 
			{ 
				return _mobileAlias; 
			}
			set 
			{
				if (value != null && value.Length > 16)
					throw new ArgumentException("Value length must be between 0 and 16 characters.");

				_mobileAlias = value;

				OnRowChanged("MobileAlias");
			}
		}

		/// <summary>
		/// This property is mapped to the "IsAnonymous" field.  Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("IsAnonymous", AllowDBNull = false)]
		public bool IsAnonymous
		{
			get 
			{ 
				return _isAnonymous; 
			}
			set 
			{
				_isAnonymous = value;

				OnRowChanged("IsAnonymous");
			}
		}

		/// <summary>
		/// This property is mapped to the "LastActivityDate" field.  Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("LastActivityDate", AllowDBNull = false)]
		public DateTime LastActivityDate
		{
			get 
			{ 
				return _lastActivityDate; 
			}
			set 
			{
				_lastActivityDate = value;

				OnRowChanged("LastActivityDate");
			}
		}

		#endregion

		#region IObjectNotification Members

		/// <summary>
		/// Invoked by the framework before the persistent object is populated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforePopulated(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is populated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterPopulated(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is inserted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeInsert(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is inserted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterInsert(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is updated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeUpdate(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is updated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterUpdate(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeDelete(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterDelete(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object has been marked deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeMarkDeleted(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object has been marked deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterMarkDeleted(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		#endregion

		#region ISelfContainingObject Members

		private ObjectInfo _objectInfo = null;

		/// <summary>
		/// Returns the <see cref="Opf3.ObjectInfo">ObjectInfo</see> object that contains all
		/// information required to make the persistent object
		/// <see cref="Opf3.ObjectContext">independent from any ObjectContext</see>.
		/// </summary>
		/// <value>
		/// 	<see cref="Opf3.ObjectInfo">ObjectInfo</see> object that holds the status
		/// information of the persistent object.
		/// </value>
		ObjectInfo ISelfContainingObject.ObjectInfo
		{
			get { return _objectInfo; }
			set { _objectInfo = value; }
		}

		#endregion

		#region INotifyPropertyChanged Members

		/// <summary>
		/// Invokes the "PropertyChanged" event if a property has been changed and
		/// somebody subscribed the event.
		/// </summary>
		private void OnRowChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		/// <summary>
		/// Event is fired if a property of the persistent changed.
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}
